<template>
  <div>
    <div class="table-page-search-wrapper">
      <a-form-model
        layout="inline"
        :model="queryParam"
      >
        <a-row :gutter="15">
          <a-col :md="6" :sm="24">
            <a-form-model-item label="被叫">
              <a-input v-model="queryParam['filter[dst]']"/>
            </a-form-model-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-model-item label="通讯账号">
              <a-select
                v-model="queryParam['filter[adviser_nanfang_accounts]']"
                placeholder="选择通讯账号"
              >
                <a-select-option v-for="(item,index) in accountOpts" :key="item" :value="item">{{index}}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-model-item label="通时区间">
              <a-select v-model="queryParam['filter[nanfang_section]']" placeholder="选择对应的通时区间">
                <a-select-option v-for="(item,index) in sectionOpts" :key="index" :value="index">{{item}}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-button type="primary" @click="$refs.table.refresh(true)">搜索</a-button>
          <a-button style="margin-left: 8px" @click="resetForm">重置</a-button>
        </a-row>
      </a-form-model>
    </div>
    <div class="table-operator">
      <s-table
        bordered
        ref="table"
        :row-key="(record) => record.id"
        :columns="nfColumns"
        :data="nfData"
      >
        <template slot="url" slot-scope="text, record">
          <audio v-if="record.duration != 0" :src="text" controls :style="{ height: '20px', lineHeight: '20px' }">
            您的浏览器不支持 audio 标签
          </audio>
          <div v-else>
            -
          </div>
        </template>
      </s-table>
    </div>
  </div>
</template>

<script>
import { STable } from '@/components'
import col from '@/columns/calls'
import { getCallList } from '@/api/calls'
const nfColumns = col.nanfang

export default {
  components: {
    STable
  },
  name: 'NanFang',
  data () {
    return {
      nfColumns,
      nfData: parameters => {
        return getCallList(Object.assign(parameters, this.queryParam)).then(res => {
          this.sectionOpts = res.result.nanfang_section
          this.accountOpts = res.result.nanfang_account
          return res.result
        })
      },
      queryParam: {},
      accountOpts: {},
      sectionOpts: {}
    }
  },
  created () {
    this.queryParam['filter[type]'] = '2'
  },
  methods: {
    resetForm () {
      const app = this
      app.queryParam = {}
      app.queryParam['filter[type]'] = '2'
      app.$refs.table.refresh(true)
    }
  }
}
</script>

<style scoped>

</style>
